#ifndef TIMER_H
#define TIMER_H

#include "core_global.h"
#include <boost/noncopyable.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/function.hpp>

class Timer : protected boost::noncopyable
{
public:
    typedef boost::asio::io_service ServiceImpl;
    typedef boost::asio::deadline_timer DeadlineTimer;

    typedef boost::function< void (unsigned int, unsigned int) > Notifier;

public:
    Timer(ServiceImpl &service);
    ~Timer();

    unsigned int owner();

    unsigned int id();

    unsigned long elapse();

    unsigned int repeat();

    void setOwner(unsigned int owner);

    void setId(unsigned int id);

    void setElapse(unsigned long elapse);

    void setRepeat(unsigned int repeat);

    void start(BOOST_ASIO_MOVE_ARG(Notifier) handler);

    void stop();

private:
    DeadlineTimer m_impl;

    unsigned int m_owner;

    unsigned int m_id;

    unsigned long m_elapse;

    unsigned int m_repeat;
};

#endif // TIMER_H
